package com.wiscamp.ninechapters.problems.math;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 根数
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class LatexRadicalNumber extends LatexNumber {
    /**
     * 根号下的数
     */
    private int number = 0;

    /**
     * 根式的根
     */
    private int root = 0;

    /**
     * 根号前的数
     */
    private int prefixNumber = 0;

    /**
     * 根数前的正负号
     */
    private String symbol = "";


    public String getLatex() {
        if (symbol.equals("+"))
            symbol = "";
        var tempText = "";
        if (prefixNumber != 0) {
            tempText = String.format("%s%s\\sqrt[%d]{%d}", symbol, prefixNumber, root, number);
        } else {
            tempText = String.format("%s\\sqrt[%d]{%d}", symbol, root, number);
        }
        if (tempText.contains("[2]"))
            tempText = tempText.replace("[2]", "");
        return tempText;
    }

    public LatexRadicalNumber() {

    }

    public LatexRadicalNumber(String symbol, int prefixNumber, int root, int number) {
        this.symbol = symbol;
        this.prefixNumber = prefixNumber;
        this.root = root;
        this.number = number;
    }
}
